<template>
  <q-list separator class="q-py-none" :no-border="$q.platform.is.mobile"> 
    <q-item>
      <q-item-side icon="mdi-douban" />
      <q-item-main label style="min-width:50px;">活动</q-item-main>
      <q-item-side right style="flex:0 1 auto">{{value.name}}</q-item-side>
      <q-item-side right style="flex:0 1 auto">
        <q-btn v-if="value.owner == 'joearde'" @click="plusOnline" 
                dense outline label="PLUS上线" color="primary" class="q-mx-sm" />
        <q-btn v-if="value.owner == 'plus-home'" @click="plusOffline" 
                dense outline label="PLUS下线" color="black" class="q-mx-sm" />
      </q-item-side>
    </q-item>
    <q-item>
      <q-item-side icon="mdi-movie" />
      <q-item-main label style="min-width:50px;">影片</q-item-main>
      <q-item-side right style="flex:0 1 auto">{{value.movieName}}</q-item-side>
    </q-item>
    <q-item>
      <q-item-side icon="mdi-account-location" />
      <q-item-main label style="min-width:50px;">负责人</q-item-main>
      <q-item-side right style="flex:0 1 auto">{{value.managers.length == 0 ? '(暂未设置)' : value.managers.join(',')}}</q-item-side>
      <q-item-side right style="flex:0 1 auto" 
        v-if="value.managers.join(',').indexOf(this.$api.account.localAccount().name)<0">
        <q-btn dense outline label="我是负责人" color="primary" class="q-mx-sm"  
                  @click="addManager" />
      </q-item-side>
    </q-item>
    <q-item>
      <q-item-side icon="mdi-calendar-clock" />
      <q-item-main label style="min-width:50px;">开场时间</q-item-main>
      <q-item-side right style="flex:0 1 auto">{{value.date}} {{value.time}}</q-item-side>
    </q-item>
    <q-item>
      <q-item-side icon="spellcheck" />
      <q-item-main label style="min-width:50px;">签到时间</q-item-main>
      <q-item-side right style="flex:0 1 auto">
        <q-input class="full-width" type="number" hide-underline v-model="value.checkBeforeMinutes" 
            :float-label="'开场前' + value.checkBeforeMinutes + '分钟开始签到'" 
            @input="updateInterval" />        
      </q-item-side>
    </q-item>
    <q-item>
      <q-item-side icon="mdi-city" />
      <q-item-main label style="min-width:50px;">地点</q-item-main>
      <q-item-side right style="flex:0 1 auto">{{value.place}}</q-item-side>
    </q-item>
    <q-item>
      <q-item-side icon="mdi-barcode" />
      <q-item-main label style="min-width:50px;">小程序码</q-item-main>
      <q-item-side right style="flex:0 1 auto">
        <q-btn dense outline label="下载活动小程序码" color="black" class="q-mx-sm"  
                  @click="downloadCode(value.id)" />
      </q-item-side>
    </q-item>
    <q-item>
      <q-item-side icon="mdi-map" />
      <q-item-main label style="min-width:50px;">影厅</q-item-main>
      <q-item-side right style="flex:0 1 auto">{{ value.hallName ? value.hallName : '(未选择)'}}</q-item-side>
      <q-item-side right style="flex:0 1 auto">
        <q-btn dense outline label="选择影厅" color="primary" class="q-mx-sm"  
                  @click="$router.push('/event/seat/'+value.id)" />
      </q-item-side>
    </q-item>
  </q-list>
</template>

<script>

export default {
  name: 'MyEventInfo',
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  methods: {
    updateInterval(v) {
      this.$api.party.updateCheckTime(this.value.id, v);
    },
    downloadCode(id) {
      let encodedPath = this.$api.base64.urlSafeEncode('subA/pages/watch/detail?id='+id+'&from=scancode');
      window.open('http://plus.nexttix.net/api/anon/mini-code?path=' + encodedPath);
    },
    addManager() {
      let me = this;
      this.$api.party.managerEvent(this.value.id, true, ret=>{
        me.value.managers.push(me.$api.account.localAccount().name);
      });
    },
    plusOnline() {
      this.value.owner = 'plus-home';
      this.$api.party.plusOnline(this.value.id, true, ret=>{});
    },
    plusOffline() {
      this.value.owner = 'joearde';
      this.$api.party.plusOffline(this.value.id, true, ret=>{});
    }
  }
}
</script>
